package com.lagou.edu.service.impl;

import com.lagou.edu.dao.entity.Token;
import com.lagou.edu.dao.repository.TokenRepository;
import com.lagou.edu.service.TokenServiceApi;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.Optional;

/**
 * @author bobcheng
 * @date 2020/7/13
 */
@Service
public class TokenServiceApiImpl implements TokenServiceApi {

    @Autowired
    private TokenRepository tokenRepository;

    @Override
    public String info(String token) {
        Optional<Token> optional = Optional.ofNullable(tokenRepository.findTopByToken(token));
        return optional.map(Token::getEmail).orElse(null);
    }
}
